import core.IPerson;
import core.PersonImpl;
import core.PersonProxyUtil;

import java.util.Hashtable;


/**
 * describe:
 *
 * @author helloworldyu
 * @data 2018/3/26
 */
public class MatchMakingTestDrive {
	Hashtable datingDB = new Hashtable();

	public static void main(String[] args) {
		MatchMakingTestDrive test = new MatchMakingTestDrive();
		test.drive();
	}

	public MatchMakingTestDrive() {
		initializeDatabase();
	}

	public void drive() {
		IPerson joe = getPersonFromDatabase("Joe Javabean");
		IPerson ownerProxy = PersonProxyUtil.getOwnerProxy(joe);
		System.out.println("Name is " + ownerProxy.getName());
		ownerProxy.setInterests("bowling, Go");
		System.out.println("Interests set from owner proxy");
		try {
			ownerProxy.setHotOrNotRating(10);
		} catch (Exception e) {
			System.out.println("Can't set rating from owner proxy");
			e.printStackTrace();
		}
		System.out.println("Rating is " + ownerProxy.getHotOrNotRating());

		IPerson nonOwnerProxy = PersonProxyUtil.getNonOwnerProxy(joe);
		System.out.println("Name is " + nonOwnerProxy.getName());
		try {
			nonOwnerProxy.setInterests("bowling, Go");
		} catch (Exception e) {
			System.out.println("Can't set interests from non owner proxy");
			e.printStackTrace();
		}
		nonOwnerProxy.setHotOrNotRating(3);
		System.out.println("Rating set from non owner proxy");
		System.out.println("Rating is " + nonOwnerProxy.getHotOrNotRating());
	}

	IPerson getPersonFromDatabase(String name) {
		return (IPerson)datingDB.get(name);
	}

	void initializeDatabase() {
		IPerson joe = new PersonImpl();
		joe.setName("Joe Javabean");
		joe.setInterests("cars, computers, music");
		joe.setHotOrNotRating(7);
		datingDB.put(joe.getName(), joe);

		IPerson kelly = new PersonImpl();
		kelly.setName("Kelly Klosure");
		kelly.setInterests("ebay, movies, music");
		kelly.setHotOrNotRating(6);
		datingDB.put(kelly.getName(), kelly);
	}
}